import { composeStories } from '@storybook/testing-react';
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
import { test, expect, describe } from 'vitest';

import * as stories from './Tooltip.stories';

const { Bottom, Top, Left, Right } = composeStories(stories);

const toolTipContainer = 'test-tooltip';
const toolTipContent = 'test-tooltip-content';

test('Tooltip - Bottom', async () => {
    render(<Bottom />);

    // should render widget
    const container = screen.getByTestId(toolTipContainer);
    expect(container).not.toBeNull();

    // should show text on hover
    fireEvent.mouseOver(screen.getByTestId(toolTipContent));

    const childrenContainer = await waitFor(() =>
        screen.getByTestId(toolTipContainer),
    );
    expect(childrenContainer).toBeDefined();
});

test('Tooltip - Top', async () => {
    render(<Top />);

    // should render widget
    const container = screen.getByTestId(toolTipContainer);
    expect(container).not.toBeNull();

    // should show text on hover
    fireEvent.mouseOver(screen.getByTestId(toolTipContent));

    const childrenContainer = await waitFor(() =>
        screen.getByTestId(toolTipContainer),
    );
    expect(childrenContainer).toBeDefined();
});

test('Tooltip - Right', async () => {
    render(<Right />);

    // should render widget
    const container = screen.getByTestId(toolTipContainer);
    expect(container).not.toBeNull();

    // should show text on hover
    fireEvent.mouseOver(screen.getByTestId(toolTipContent));

    const childrenContainer = await waitFor(() =>
        screen.getByTestId(toolTipContainer),
    );
    expect(childrenContainer).toBeDefined();
});

test('Tooltip - Left', async () => {
    render(<Left />);

    // should render widget
    const container = screen.getByTestId(toolTipContainer);
    expect(container).not.toBeNull();

    // should show text on hover
    fireEvent.mouseOver(screen.getByTestId(toolTipContent));

    const childrenContainer = await waitFor(() =>
        screen.getByTestId(toolTipContainer),
    );
    expect(childrenContainer).toBeDefined();
});
